<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'admin.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link rel="stylesheet" href="css/pintuer.css">
<link rel="stylesheet" href="css/admin.css">
<script src="js/jquery.js"></script>
<script src="js/pintuer.js"></script>

</head>

<body>
	<div class="panel admin-panel">
		<div class="panel-head">
			<strong><span class="icon-key"></span> 修改管理员密码</strong>
		</div>
		<div class="body-content">
			<form method="post" class="form-x">
				<div class="form-group">
					<div class="label">
						<label for="sitename">管理员帐号：</label>
					</div>
					<div class="field">
						<label style="line-height: 33px;"> ${account} <input
							type="text" value="${account}" id="account"
							style="display: none;" name="admijnAccount">
						</label>
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label for="sitename">原始密码：</label>
					</div>
					<div class="field">
						<input type="password" name="oldPassword" class="input w50"
							id="mpass" name="mpass" size="50" placeholder="请输入原始密码"
							data-validate="required:请输入原始密码" />
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label for="sitename">新密码：</label>
					</div>
					<div class="field">
						<input type="password" id="opwd" class="input w50"
							 size="50" placeholder="请输入新密码"
							data-validate="required:请输入新密码,length#>=5:新密码不能小于5位" />
					</div>
				</div>
				<div class="form-group">
					<div class="label">
						<label for="sitename">确认新密码：</label>
					</div>
					<div class="field">
						<input type="password" id="npwd" name="adminPassword" class="input w50"
							size="50" />
					</div>
				</div>

				<div class="form-group">
					<div class="label">
						<label></label>
					</div>
					<div class="field">
						<button class="button bg-main icon-check-square-o" type="submit">
							提交</button>
					</div>
				</div>
			</form>
		</div>
	</div>


</body>
<script type="text/javascript">
	function jsonAdmins(admijnaccount, adminpassword) {
		this.admijnaccount = admijnaccount;
		this.adminpassword = adminpassword;
	}

	$("#mpass").click(function() {
		console.log("hehe");

		var account = $("#account").val();
		var pwd = $("#mpass").val();

		var jsonadmins = new jsonAdmins(account, pwd);

		var admins = JSON.stringify(jsonadmins);
		$.ajax({

			type : 'post',

			url : '/admin/check.do',

			dataType : "json",
			/*
			          必须要加的属性
			           要求为String类型的参数，当发送信息至服务器时，内容编码类型默认为"application/x-www-form-urlencoded"。该默认值适合大多数应用场合。
			           当发送的数据格式为json时，设置的编码类型为："application/json; charset=utf-8" 
			 */
			contentType : "application/json",
			/*
			要求为Boolean类型的参数，默认设置为true，所有请求均为异步请求。如果需要发送同步请求，请将此选项设置为false。注意，同步请求将锁住浏览器，用户其他操作必须等待请求完成才可以执行。
			 */
			async : true,

			data : admins,

			success : function(data) {

				if (data === false) {

					alert("密码错误请重新输入");

				}

				else {

					alert("密码正确可以修改");

				}

			}

		});

	});
	
	$("#npwd").blur(function(){
    var npwd=$("#npwd").val();
    var opwd=$("#opwd").val();
    if(npwd!=opwd){
      alert("新旧密码不一致");		
    }
    });
	$("button:submit").click(function(){
    var account = $("#account").val();		
    var npwd=$("#npwd").val();
 	var admins=new jsonAdmins(account,npwd);
    // /admin/update.do
	$.ajax({
		type:"post",
		
		url: '/admin/check.do',
		
		dataType : "json",
		
		async : true,
		
		data : admins,
		
		success: function(data){
			if (data === false) {
				alert("修改失败服务器异常");
			}

			else {
                alert("修改成功");
			}
			
		}

	});
	
			
	});
	$("#npwd").blur(function(){
	    var npwd=$("#npwd").val();
	    var opwd=$("#opwd").val();
	    if(npwd!=opwd){
	      alert("新旧密码不一致");		
	    }
	    });
		$("button:submit").click(function(){
	    var account = $("#account").val();		
	    var npwd=$("#npwd").val();
	 	var jsonadmins=new jsonAdmins(account,npwd);
	 	//必须用这个函数将js对象转为json数据
	 	var admins=JSON.stringify(jsonadmins);
	    // /admin/update.do
		$.ajax({
			type:"post",
			
			url: '/admin/update.do',
			
			dataType : "json",
			contentType : "application/json",
			async : true,
			
			data : admins,
			
			success: function(data){
				console.log(hhaha);
				if (data === false) {
					alert("修改失败服务器异常");
				}
				
				else {
					console.log(hhaha);
	                alert("修改成功");
				}
				
			}

		});
		
				
		});
	

</script>
</html>
